<template>
  <div class="subject">
    <span>{{ one }}</span>
    <span>+</span>
    <span>{{ two }}</span>
    <span>=</span>
    <input type="number" v-model.number="num" :disabled="isD" />
    <button @click="submit" :disabled="isD">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      one: Math.floor(Math.random() * 10) + 1,
      two: Math.floor(Math.random() * 10) + 1,
      num: "",
      isD: false,
    };
  },
  methods: {
    submit() {
      this.isD = true;
      let result = this.one + this.two == this.num ? "正确" : "错误";
      this.$emit("result", result, this.index);
    },
  },
  props: ["index"],
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>